<?php

//use yii\web\View;

use yii\helpers\Url;

?>
<?php echo $this->render("/layouts/top")?>

<style>



</style>
<script type="text/javascript" src="/js/NoLimitCategory.js"></script>

<div style="margin: 0px auto; width:1000px;">
    <h1>翻页采集任务</h1>
    <input id="task_create" type="button" value="创建任务"/>
</div>

<table width="1000" align="center" border="0" cellpadding="2" cellspacing="1">

    <tr bgcolor=#DFDFDF>
        <td>ID</td>
        <td width=180>任务名</td>
        <td>实现类</td>
        <td>总页数</td>
        <td>编辑</td>
    </tr>

    <?php
        foreach($tasks as $task){
            ?>
            <tr bgcolor=#EFEFEF>
                <td width=120><?php echo $task["id"]?></a></td>
                <td><a href="index.php/upload/multImage" target="_blank"><?php echo $task["name"]?></a></td>
                <td><?php echo $task["impl_class"]?></td>
                <td><?php echo $task["page_sum"]?></td>
                <td><a href="<?php echo Url::to(["detail", "id"=>$task["id"]])?>">进入</a>
                    <a href="javascript:void(0)" onclick="edit(<?php echo $task["id"]?>)">编辑</a>
                    <a href="javascript:void(0)" onclick="remove(<?php echo $task["id"]?>)">删除</a>
                </td>
            </tr>
            <?php
        }
    ?>

</table>
<br>
<script language="JavaScript">

    function edit(id){
        console.log(id);
        layer.open({
            type: 2,
            title: 'layer mobile页',
            shadeClose: true,
            shade: 0.8,
            area: ['640px', '90%'],
            content: '<?php echo Url::to(["edit"])?>'+'?id='+id,
        });
    }

    function remove(id){
        if(confirm("确定要删除？")){
            $.ajax({
                url : "<?php echo Url::to(["async-remove"])?>",
                type : 'GET',
                dataType : 'json',
                data : {
                    id : id,
                },
                success : function (result) {
                    console.log(result);
                    if(result.code == 200){
                        alert("删除成功");
                        window.location.reload();
                    }else{
                        alert(result.info);
                    }
                }
            });
        }
    }

    $(document).ready(function () {

        $('#task_create').on('click', function () {
            layer.open({
                type: 2,
                title: 'layer mobile页',
                shadeClose: true,
                shade: 0.8,
                area: ['640px', '90%'],
                content: '<?php echo Url::to(["edit"])?>' //iframe的url
            });
        });
    });



</script>

<?php echo $this->render("/layouts/footer")?>
